home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -readerstuff- / james_boyd / rogobox.asc < prev    next >
Text File  |  2000-03-04  |  31KB  |  1,110 lines

  1. .
  2. .RogoboxInfo
  3.  
  4. ; Rogobox - "RollOver - GOod BOy!" + X :)
  5. ;            ^   ^      ^^   ^^      ^
  6. ; Javascript rollover generator
  7. ; (Public Domain program and source code - "DoWhatYouLikeWare"
  8. ; --
  9. ; Written by James L Boyd - thesurfaces@rockers.co.uk
  10.  
  11. ; -------------------------------------------------------------------------
  12.  
  13. ; Sections listed at right side of screen:
  14.  
  15. ; RogoboxInfo - Basic information about Rogobox
  16. ; ToDo        - Still to be coded/ideas
  17. ; CompileInfo - Information for Blitz programmers
  18. ; History     - Program history/changes
  19. ; LibChecks   - Check for required libraries
  20. ; Funcs       - Reused code in statements and functions
  21. ; TopOfCode   - Start of main code (& version strings)
  22. ; Prefs       - Tooltype code
  23. ; IMPORTANT   - Change when developing/compiling executables
  24. ; Variables   - Main variables
  25. ; MainLoop    - Main loop (duh!)
  26. ; Gosubs      - stuff that went into Gosubs easier (don't ask ;)
  27. ; HTMLDemo    - the generated HTML code
  28.  
  29. ; -------------------------------------------------------------------------
  30. .
  31. .ToDo ; In no particular order:
  32.  
  33. ; Go all reqtools?
  34.  
  35. ; Optimise for executable size
  36.  
  37. ; Add other Javascript features [ NEW PROGRAM! ]
  38.  
  39. ; -------------------------------------------------------------------------
  40. .
  41. .CompileInfo
  42.  
  43. ; * * * * I M P O R T A N T ! * * * *
  44.  
  45. ; Make sure you comment out the section at the
  46. ; .IMPORTANT label before creating an executable!
  47.  
  48. ; Make sure you have Blitzlibs:amigalibs.res set in
  49. ; your Compiler Options! This code uses the Blitz
  50. ; reqtools includes, as well as some OS structures.
  51.  
  52. ; Newly added reqtools constants. The weird thing is that
  53. ; my setup works even with this stuff disabled; some other
  54. ; people's setups don't. Yet I don't get any "Duplicated
  55. ; constant" kind of errors! Oh, well...
  56.  
  57.   #RT_TagBase     =#TAG_USER
  58.   #RT_Window      =(#RT_TagBase+1)
  59.   #RT_ReqPos      =(#RT_TagBase+3)
  60.   #RT_LockWindow  =(#RT_TagBase+13)
  61.   #REQPOS_POINTER =0
  62.  
  63.   #RTGL_GadFmt    =(#RT_TagBase+34)
  64.   #RTGS_GadFmt    =#RTGL_GadFmt
  65.  
  66.   #RTGL_TextFmt   =(#RT_TagBase+38)
  67.   #RTGS_TextFmt   =#RTGL_TextFmt
  68.  
  69.   #RTGL_BackFill  =(#RT_TagBase+37)
  70.   #RTGS_BackFill  =#RTGL_BackFill
  71.  
  72.   #RTEZ_Flags     =(#RT_TagBase+22)
  73.   #RTGL_Flags     =#RTEZ_Flags
  74.   #RTGS_Flags     =#RTGL_Flags
  75.  
  76.   #EZREQB_CENTERTEXT=2
  77.   #EZREQF_CENTERTEXT=(1LSL#EZREQB_CENTERTEXT)
  78.   #GSREQF_CENTERTEXT=#EZREQF_CENTERTEXT
  79.  
  80. ; You may well run into compile problems with the reqtools
  81. ; or datatypes stuff - the datatypes structures are defined
  82. ; in a 3rd party reworking of amigalibs.res, which is what
  83. ; is used here...
  84.  
  85. ; -------------------------------------------------------------------------
  86.  
  87. ; Doing your own version?
  88.  
  89. ; Feel free to release your own, but please use
  90. ; a different name to Rogobox!
  91.  
  92. ; -------------------------------------------------------------------------
  93. .
  94. .History
  95.  
  96. ; Lists Rogobox code changes, plus generated
  97. ; HTML/Javascript changes. Last changes at top.
  98.  
  99. ; ---------------------------------------
  100.  
  101. ; Rogobox 1.2
  102. ; 23 February 2000
  103.  
  104. ; Program changes:
  105. ; ----------------
  106.  
  107. ;   Added insertion of image WIDTH & HEIGHT
  108. ;   attributes via datatypes.
  109.  
  110. ;   Because of above, now requires OS3.x. See
  111. ;   if this can be avoided by skipping datatype
  112. ;   code...?
  113.  
  114. ; Generated HTML changes:
  115. ; -----------------------
  116.  
  117. ;   Added WIDTH & HEIGHT attributes.
  118.  
  119. ; ---------------------------------------
  120.  
  121. ; Rogobox 1.1
  122. ; 13 February 2000
  123.  
  124. ; Program changes:
  125. ; ----------------
  126.  
  127. ;   Changed Javascript rollover code (see HTML changes).
  128.  
  129. ;   Added reqtools.library check (it's just above .Funcs).
  130.  
  131. ;   Removed redundant "invisible text" constant from
  132. ;   RTGetString function.
  133.  
  134. ;   Added reqtools constants used, after Curt Esser
  135. ;   reported that the include line didn't, er, INCLUDE
  136. ;   what it was supposed to!
  137.  
  138. ;   Changed name to Rogobox - it's now going to be
  139. ;   a general purpose Javascript gimmick creator :)
  140. ;   (Future: scrolling text, colour text rollovers, etc.)
  141.  
  142. ;   Created Amigaguide documentation.
  143.  
  144. ;   Altered About requester to show version.
  145.  
  146. ;   Made Load Image/Save HTML paths independent.
  147.  
  148. ;   Put Quit and About routines into functions,
  149. ;   to save executable size and remove duplicated
  150. ;   code.
  151.  
  152. ;   Opens on any public screen.
  153.  
  154. ;   Adjusted Quit and New Project requesters to be
  155. ;   more intelligent (ie whether they pop up or not).
  156.  
  157. ;   Added tooltype options:
  158.  
  159. ;     AUTONAME     - TRUE|FALSE     - no prompt for rollover names
  160. ;     ALT          - IMAGE|JS       - ALT uses filename or JS name
  161. ;     PUBSCREEN    - [public screen name or ASKME for a list]
  162. ;     BORDER       - [0-xxxx]       - image borders
  163. ;     IMAGESIZES   - TRUE|FALSE     - get image sizes via datatypes
  164. ;     DEFAULTLINK  - [url]          - default image link URL
  165. ;     PRELOAD      - TRUE|FALSE     - image preloading code
  166. ;     IMAGEPATH    - [path to picture directory, defaults to RAM:]
  167. ;     SAVEPATH     - [path to save directory,    defaults to RAM:]
  168. ;     NOLINKS      - TRUE|FALSE     - JS code for null links
  169.  
  170. ;     Functions currently working:
  171.  
  172. ;     AUTONAME
  173. ;     ALT
  174. ;     PUBSCREEN
  175. ;     BORDER
  176. ;     IMAGESIZES
  177. ;     DEFAULTLINK
  178. ;     PRELOAD
  179. ;     IMAGEPATH
  180. ;     SAVEPATH
  181. ;     NOLINKS
  182.  
  183. ; Generated HTML changes:
  184. ; -----------------------
  185.  
  186. ;   Bob Akerberg let me know that the old code didn't
  187. ;   work in IBrowse 2, whereas the replacement code he
  188. ;   sent me works in all 3 main Amiga browsers, plus
  189. ;   the "Big Two" PC browsers. It also makes for much
  190. ;   smaller HTML when using multiple rollovers - thanks,
  191. ;   Bob!
  192.  
  193. ;   Added null link code.
  194.  
  195. ;   Added image preloading.
  196.  
  197. ;   Adjusted HTML layout slightly.
  198.  
  199. ;   Added HTML/Javascript comments.
  200.  
  201. ; ---------------------------------------
  202.  
  203. ; Rogobox 1.0
  204. ; 7 February 2000
  205.  
  206. ; Program changes:
  207. ; ----------------
  208.  
  209. ;   First release version.
  210.  
  211. ; Generated HTML changes:
  212. ; -----------------------
  213.  
  214. ;   First release code.
  215.  
  216. ; -------------------------------------------------------------------------
  217. .
  218. .LibChecks
  219.  
  220. ; Check for required libraries - placed here cos I'm not sure
  221. ; if the functions will be affected if any aren't on the
  222. ; system...and I can't be bothered checking :)
  223.  
  224. ; Check if we're on OS3.x for datatype stuff:
  225.  
  226.   e$="exec.library"
  227.   *lib.Library=OpenLibrary_(&e$,0)
  228.   If *lib
  229.     v.w=*lib\lib_Version            ; Kickstart version
  230.     CloseLibrary_ *lib
  231.   EndIf
  232.  
  233.   usedt.b=0                         ; Datatype usage flag
  234.  
  235.   If v>38                           ; Only if we're on OS3.x
  236.     *lib.Library=OpenLibrary_("datatypes.library",39)
  237.     If *lib
  238.       usedt.b=-1                    ; We can use datatypes :)
  239.       CloseLibrary_ *lib
  240.     Else
  241.       error$="WARNING:||You need datatypes.library 39+||You won't be able to use|datatypes to get image info!"
  242.       Request "Rogobox",error$,"Oh..."
  243.     EndIf
  244.   EndIf
  245.  
  246. ; Easy way to add more library checks in future:
  247.  
  248.   nolibs.b=1
  249.  
  250.   Dim LibsToCheck$ (nolibs)
  251.   Dim LibVersion.b (nolibs)
  252.  
  253.   LibsToCheck$(1) = "reqtools.library"
  254.   LibVersion  (1) = 38
  255.  
  256. ; Add more like this:
  257.  
  258. ;  LibsToCheck$(x) = "[libraryname.library]"
  259. ;  LibVersion  (x) = version
  260.  
  261. ; Now we can check 'em all in a "oner". We do this by
  262. ; attempting to open each one in turn and closing it if
  263. ; successful (Blitz opens libraries itself), or making
  264. ; note of any that don't open:
  265.  
  266.   For a.b=1 To nolibs
  267.     *lib.Library=OpenLibrary_(&LibsToCheck$(a),LibVersion(a))
  268.     If *lib
  269.       CloseLibrary_ *lib
  270.     Else
  271.       liberror$+LibsToCheck$(a)+", version "+Str$(LibVersion(a))+".|"
  272.     EndIf
  273.   Next a
  274.  
  275.   If liberror$                      ; List all libraries needed
  276.     liberror$=Left$(liberror$,Len(liberror$)-1)
  277.     Request "Rogobox","You need the following libraries installed:||"+liberror$,"Abort"
  278.     End
  279.   EndIf
  280.  
  281. ; -------------------------------------------------------------------------
  282. .
  283. .Funcs
  284.  
  285. ; Functions & Statements
  286.  
  287. ; (...and no, I can't be bothered commenting them!)
  288.  
  289. ; -------------------------------------------------------------------------
  290.  
  291. Function$ ToolString {icon$,tool$}
  292.   If Right$(icon$,5)=".info" Then icon$=Left$(icon$,Len(icon$)-5)
  293.   *Icon.DiskObject=GetDiskObject_(&icon$)
  294.   If *Icon
  295.     a.l=FindToolType_(*Icon\do_ToolTypes,&tool$)
  296.     If a
  297.       a$=Peek$(a)
  298.     Else a$=""
  299.     EndIf
  300.     FreeDiskObject_ *Icon
  301.   Else Function Return ""
  302.   EndIf
  303.   Function Return a$
  304. End Function
  305.  
  306. ; -------------------------------------------------------------------------
  307.  
  308. ; Busy window:
  309.  
  310. Function.l LockWindow {win.l}
  311.   lock.l=AllocMem_(SizeOf .Requester,1)
  312.   If lock
  313.     win=Peek.l(Addr Window(win))
  314.     InitRequester_(lock)
  315.     If Request_(lock,win)
  316.       *Exec.Library=Peek.l(4)
  317.       If *Exec\lib_Version=>39
  318.         Dim tag.TagItem(1)
  319.         tag(0)\ti_Tag=#WA_BusyPointer,-1
  320.         tag(1)\ti_Tag=#TAG_END
  321.         SetWindowPointerA_ win,&tag(0)
  322.       EndIf
  323.     Else
  324.       FreeMem_ lock,SizeOf .Requester
  325.       lock=0
  326.     EndIf
  327.           ; note - we'd normally free the "lock"
  328.           ; memory here, but it's needed by the
  329.           ; UnLockWindow {} function, which does
  330.           ; free it!
  331.   EndIf
  332.   Function Return lock
  333. End Function
  334.  
  335. ; -------------------------------------------------------------------------
  336.  
  337. ; un-busy window:
  338.  
  339. Statement UnlockWindow{win.l,lock.l}
  340.   win=Peek.l(Addr Window(win))
  341.   *Exec.Library=Peek.l(4)
  342.   If *Exec\lib_Version=>39
  343.     Delay_ 5
  344.     Dim tag.TagItem(0)
  345.     tag(0)\ti_Tag=#TAG_END
  346.     SetWindowPointerA_ win,&tag(0)
  347.   EndIf
  348.   EndRequest_ lock,win
  349.   FreeMem_ lock,SizeOf .Requester
  350. End Statement
  351.  
  352. ; -------------------------------------------------------------------------
  353.  
  354. ; Exists () replacement (this doesn't keep file locked!):
  355.  
  356. Function.l Exist {f$}
  357.   lock.l=Lock_(&f$,#ACCESS_READ)
  358.   If lock
  359.     DEFTYPE .FileInfoBlock fib
  360.     If Examine_(lock, fib) <> 0
  361.       If fib\fib_DirEntryType < 0
  362.         size=Peek.l(&fib\fib_Size)  ; file
  363.       Else size=-1                  ; drawer
  364.       EndIf
  365.     Else size=-2 ; failed to examine file! rare occurence!
  366.     EndIf
  367.     UnLock_ lock
  368.   Else size=0 ; failed to lock file (doesn't exist basically)...
  369.   EndIf
  370. Function Return size
  371. End Function
  372.  
  373. ; -------------------------------------------------------------------------
  374.  
  375. ; Reqtools string requester, replaces Blitz's Enforcer-hitter:
  376.  
  377. ; Reqtools structure needed:
  378.  
  379. NEWTYPE.rtReqInfo
  380.   LeftOffset.w
  381.   TopOffset.w
  382.   Width.l
  383.   ReqTitle$
  384.   Flags.l
  385.   *DefaultFont.TextFont
  386.   WaitPointer.l
  387.   LockWindow.l
  388.   ShareIDCMP.l
  389.   *IntuiMsgFunc.Hook
  390. End NEWTYPE
  391.  
  392. Function$ RTGetString {title$,body$,deftext$,maxchars.l}
  393.   body$=Replace$(body$,"|",Chr$(10))
  394.   gadget$="OK|Cancel"
  395.   #mx=8
  396.   Dim ReqTags.TagItem(#mx)
  397.   ReqTags(0)\ti_Tag   = #RT_Window,      Peek.l(Addr Window(Used Window))
  398.   ReqTags(1)\ti_Tag   = #RTGS_GadFmt,    &gadget$
  399.   ReqTags(2)\ti_Tag   = #RTGS_TextFmt,   &body$
  400.   ReqTags(3)\ti_Tag   = #RT_ReqPos,      #REQPOS_POINTER
  401.   ReqTags(4)\ti_Tag   = #RT_LockWindow,  -1
  402.   ReqTags(5)\ti_Tag   = #RTGS_BackFill,  -1
  403.   ReqTags(6)\ti_Tag   = #RTGS_Flags,     #GSREQF_CENTERTEXT
  404.   ReqTags(#mx)\ti_Tag = #TAG_DONE
  405.   DEFTYPE.rtReqInfo *reqinfo
  406.   If Peek.l(&deftext$-4) > maxchars Then maxchars=Peek.l(&deftext$-4)
  407.   res.l=maxchars/4
  408.   While Frac(res)<>0
  409.     maxchars+1
  410.     res=maxchars/4
  411.   Wend
  412.   *mem=AllocMem_(maxchars,#MEMF_PUBLIC|#MEMF_CLEAR)
  413.   If *mem
  414.     Poke$ *mem,deftext$
  415.     result.l=rtGetStringA_ (*mem,maxchars,&title$,*reqinfo,&ReqTags(0)\ti_Tag)
  416.     ret$=Peek$ (*mem)
  417.     FreeMem_ *mem,maxchars
  418.     If result
  419.       Function Return ret$
  420.     Else Function Return ""
  421.     EndIf
  422.   EndIf
  423. End Function
  424.  
  425. ; say "hey, no more rollovers!":
  426.  
  427. Statement MaxOut {}
  428.   lock.l=LockWindow {0}
  429.   Request "Rogobox","Only 128 rollovers allowed!","Better save now"
  430.   UnlockWindow {0,lock}
  431. End Statement
  432.  
  433. ; -------------------------------------------------------------------------
  434.  
  435. ; Quit request:
  436.  
  437. Function.b Quit {}
  438.   SHARED norolls.b, saved.b
  439.   If norolls>saved
  440.     lock.l=LockWindow {0}
  441.     If Request ("Rogobox","Are you sure you want to quit?","Yes|No") Then UnlockWindow {0,lock}:Function Return -1
  442.     UnlockWindow {0,lock}
  443.   Else Function Return -1
  444.   EndIf
  445. End Function
  446.  
  447. ; -------------------------------------------------------------------------
  448.  
  449. Statement About {}
  450.   SHARED v2$
  451.   lock.l=LockWindow {0}
  452.     Request "Rogobox",v2$,"OK"
  453.     UnlockWindow {0,lock}
  454. End Statement
  455.  
  456. ; -------------------------------------------------------------------------
  457.  
  458. Function$ ProgsName{}
  459.   If FromCLI
  460.     *stringbuffer = AllocMem_(255, 0)
  461.     suc.l=GetProgramName_(*stringbuffer,255)
  462.     If suc
  463.       pname$=Peek$(*stringbuffer)
  464.     EndIf
  465.     FreeMem_ *stringbuffer,255
  466.   Else pname$=Peek$(Peek.l(FindTask_(0)+$B0)+4)
  467.   EndIf
  468.   If pname$="" Then pname$="I only work when compiled!"
  469.   Function Return pname$
  470. End Function
  471.  
  472. ; -------------------------------------------------------------------------
  473.  
  474. Function$ StripQuotes {a$}
  475.   If Left$(a$,1)=Chr$(34) AND Right$(a$,1)=Chr$(34)
  476.     a$=Mid$(a$,2,Len(a$)-2) ; strip "" from string
  477.   EndIf
  478.   Function Return a$
  479. End Function
  480.  
  481. ; -------------------------------------------------------------------------
  482.  
  483. Function.s StripFile{p$}
  484.   *fileptr.l = FilePart_(&p$)
  485.   f$=Peek$(*fileptr)
  486. Function Return f$
  487. End Function
  488.  
  489. ; -------------------------------------------------------------------------
  490. .
  491. .TopOfCode
  492.  
  493. WBStartup                           ; run from an icon
  494. NoCli                               ; no Blitz CLI
  495.  
  496. ; Version string:
  497.  
  498. v1$="$VER: Rogobox 1.2 (23/02/2000) by James L Boyd "
  499.  
  500. ; Used in About requester:
  501.  
  502. v2$="Rogobox 1.2 (23/02/2000).|Javascript rollover generator.||Public domain software by James L Boyd."
  503.  
  504. ; -------------------------------------------------------------------------
  505. .
  506. .Prefs
  507.  
  508. rogobo$=ProgsName{}
  509.  
  510. ; -------------------------------------------------------------------------
  511. .
  512. .IMPORTANT
  513.  
  514. ; ENABLE THIS SECTION (following three lines) WHEN DEVELOPING;
  515.  
  516. ;If rogobo$="I only work when compiled!"
  517. ;  rogobo$="SYS:Utilities/Rogobox"    ; **** change to suit ****
  518. ;EndIf
  519.  
  520. ; **********************IMPORTANT********************************
  521. ; **** DISABLE above three lines when creating executable!!! ****
  522. ; ***************************************************************
  523.  
  524. ; -------------------------------------------------------------------------
  525.  
  526. ; Some defaults for tooltype options:
  527.  
  528. DEFTYPE.b autoname, altname, nolinks, border, imagesizes, preload
  529.  
  530. ; All set to 0 until tooltypes are read:
  531.  
  532. ; autoname    - no prompt for rollover names
  533. ; altname     - ALT attribute uses filename or rollover name
  534. ; nolinks     - no links in images - overrides defaultlink$
  535. ; border      - image border size
  536. ; imagesizes  - use datatypes to get image dimensions
  537. ; preload     - use image preloading code in Javascript
  538.  
  539. ; -------------------------------------------------------------------------
  540.  
  541. ; Get tooltype prefs:
  542.  
  543. defaultlink$  =ToolString {rogobo$,"DEFAULTLINK"}
  544.  
  545. If ToolString {rogobo$,"AUTONAME"}   ="TRUE"  Then autoname=-1
  546. If ToolString {rogobo$,"ALT"}        ="IMAGE" Then altname =-1
  547. If ToolString {rogobo$,"NOLINKS"}    ="TRUE"  Then nolinks=-1:defaultlink$=Chr$(34)+"javascript:void(0)"+Chr$(34)
  548. If ToolString {rogobo$,"PRELOAD"}    ="TRUE"  Then preload=-1
  549.  
  550. If ToolString {rogobo$,"IMAGESIZES"} ="TRUE"
  551.   If usedt Then imagesizes=-1
  552. EndIf
  553.  
  554. border=Val(ToolString {rogobo$,"BORDER"})
  555.   If border <0 Then border=0
  556.  
  557. imagepath$    =StripQuotes{ToolString {rogobo$,"IMAGEPATH"}}
  558.   If Exist {imagepath$}=0 Then imagepath$="RAM:"
  559.  
  560. savepath$     =StripQuotes{ToolString {rogobo$,"SAVEPATH"}}
  561.   If Exist {savepath$}=0 Then savepath$="RAM:"
  562.  
  563. pubscreen$    =StripQuotes{ToolString {rogobo$,"PUBSCREEN"}}
  564.  
  565. ; -------------------------------------------------------------------------
  566.  
  567. ; tooltype checker:
  568.  
  569. ; a$="autoname="+Str$(autoname)
  570. ; a$+"|altname="+Str$(altname)
  571. ; a$+"|nolinks="+Str$(nolinks)
  572. ; a$+"|imagesize="+Str$(imagesize)
  573. ; a$+"|border="+Str$(border)
  574. ; a$+"|defaultlink="+defaultlink$
  575. ; a$+"|pubscreen="+pubscreen$
  576.  
  577. ; Request "",a$,"OK"
  578. ; End
  579.  
  580. ; -------------------------------------------------------------------------
  581.  
  582. ; Find screen:
  583.  
  584. If pubscreen$<>"ASKME" Then ask.b=0 Else ask=-1
  585. If pubscreen$="" Then pubscreen$="Workbench"
  586.  
  587. Pubscreens                          ; If screen isn't found,
  588.                                     ; we come back here
  589. ; See if public screen exists:
  590.  
  591. noscreen.b=0                        ; Used if screen not found
  592.  
  593. Dim scr$(127)                       ; To be on the safe side ;)
  594. *scrs.List=LockPubScreenList_ ()
  595.   *mynode.Node=*scrs\lh_Head
  596.   count.w=0
  597.   While *mynode\ln_Succ
  598.     count+1
  599.     scr$(count)=Peek$(*mynode\ln_Name)
  600.     If scr$(count)=pubscreen$ Then Goto skipscreens
  601.     *mynode=*mynode\ln_Succ
  602.   Wend
  603.   pubscreen$="Workbench"            ; Used if not in list
  604.   noscreen=-1
  605.   skipscreens
  606. UnlockPubScreenList_
  607.  
  608. ; -------------------------------------------------------------------------
  609.  
  610. ; Pubscreen list:
  611.  
  612.   For a=1 To count:sc$+Str$(a)+": "+scr$(a)+"|":Next a
  613.   sc$=Left$(sc$,Len(sc$)-1)         ; strip last "|"
  614.  
  615. ; -------------------------------------------------------------------------
  616.  
  617. If noscreen
  618.  
  619.   If count=1
  620.     req$=scr$(1)+"|Abort"           ; only one screen open
  621.   Else For a=1 To count:req$+Str$(a)+"|":Next a:req$+"Abort"
  622.   EndIf
  623.  
  624.   If ask=0
  625.     info$="The screen you requested wasn't found.||Existing public screens:||"+sc$
  626.   Else info$="Choose a screen to open on:||"+sc$
  627.   ; This appears if the user has PUBSCREEN="ASKME"
  628.   EndIf
  629.  
  630.   a=Request ("Rogobox",info$,req$)
  631.   If a
  632.     pubscreen$=scr$(a)
  633.     Goto Pubscreens
  634.   Else End
  635.   EndIf
  636. EndIf
  637.  
  638. ; Crunch time - open on screen or quit:
  639.  
  640. *grabscreen.Screen=LockPubScreen_ (&pubscreen$)
  641.   If *grabscreen
  642.     *scr.Screen=*grabscreen         ; not 100% sure if UnlockPubScreen keeps the pointer...I think it does, but... ;)
  643.     title$=Peek$(*grabscreen\Title)
  644.     FindScreen 0,title$             ; get public screen
  645.     UnlockPubScreen_ 0,*grabscreen
  646.   Else Request "Rogobox","Can't lock ANY public screen!","Abort"
  647.     End
  648.   EndIf
  649.  
  650. ; -------------------------------------------------------------------------
  651.  
  652. ; Screen info/font sensitivity:
  653.  
  654. ScreenToFront_ *scr
  655.  
  656.   sw.w=*scr\Width                   ; screen width
  657.   sh.w=*scr\Height                  ; screen height
  658.   bh.b=*scr\BarHeight+1             ; title bar height
  659.   lb.b=*scr\WBorLeft                ; window left border
  660.   rb.b=*scr\WBorRight               ; window right border
  661.   *scfont.TextAttr=*scr.Screen\Font ; screen's font
  662.  
  663. fheight.b=(*scfont.TextAttr\ta_YSize)  ; font height
  664. fname$=Peek$(*scfont.TextAttr\ta_Name) ; font name
  665. LoadFont f,fname$,fheight              ; use screen's font
  666.  
  667. gw.w=300     ; width of gadgets
  668. pad.b=3      ; gadget text padding (above & below text)
  669. gh.b=bh+pad  ; gadget height (= title bar + padding)
  670.  
  671. GTButton 0,0,-lb,-bh,gw,gh,"Create new rollover",0 ; first button
  672. GTButton 0,1,-lb,pad,gw,gh,"Save rollover HTML",0  ; second button
  673. GTButton 0,2,-lb,bh+pad*2,gw/2,gh,"About",0        ; third button
  674. GTButton 0,3,(gw/2-lb),bh+pad*2,gw/2,gh,"Quit",0   ; fourth button
  675.  
  676. ; ^^^ "Trial and error does it every time" ;)
  677.  
  678. numgadshi.b=3 ; number of rows of gadgets the following
  679.               ; lines will magically adjust the window's
  680.               ; height to fit :)
  681.  
  682. ww.w=gw+lb+rb                       ; calculate window width
  683. wh.w=(gh)*(numgadshi+1)-(pad-2)     ; calculate window height
  684.  
  685. wx.w=(sw/2)-(ww/2)                  ; centre window x position
  686. wy.w=(sh/2)-(wh/2)                  ; centre window y position
  687.  
  688. ; -------------------------------------------------------------------------
  689.  
  690. ; Gadtools menus space themselves out properly!
  691.  
  692. ; You need the Ultimate Blitz Basic CD for the GTMenu library;
  693. ; to use normal Blitz menus, just remove the "GT" from the
  694. ; start of the following commands (plus GTSetMenu beneath
  695. ; the Window command).
  696.  
  697. GTMenuTitle 0,0,"Project"
  698. GTMenuItem  0,0,0,0,"New Project","N"
  699. GTMenuItem  0,0,0,1,"About Rogobox...","A"
  700. GTMenuItem  0,0,0,2,"Quit Rogobox...","Q"
  701.  
  702. GTMenuTitle 0,1,"Rollovers"
  703. GTMenuItem  0,0,1,0,"Create new...","C"
  704. GTMenuItem  0,0,1,1,"Save HTML...","S"
  705.  
  706. ; -------------------------------------------------------------------------
  707.  
  708. ; Open window:
  709.  
  710. ; Some versions of Blitz don't allow the "window open" check,
  711. ; so just uncomment the next line if this applies to you,
  712. ; and comment out the following four lines:
  713.  
  714. ; Window 0,wx,wy,ww,wh,$20140e,"Rogobox",1,2
  715.  
  716. If Window (0,wx,wy,ww,wh,$20140e,"Rogobox",1,2)=0
  717.   Request "Rogobox","Rogobox couldn't open its window!","Abort"
  718.   End
  719. EndIf
  720.  
  721. AttachGTList 0,0                    ; attach gadgets
  722. GTSetMenu 0                         ; attach gadtools menus
  723.  
  724. ; -------------------------------------------------------------------------
  725. .
  726. .Variables
  727.  
  728. ; Main variables:
  729.  
  730. #maxrolls=127                   ; max number of rollovers (keep in a byte ;)
  731.  
  732. ; newbies beware! if you increase this number,
  733. ; you need to know what you're doing with bytes,
  734. ; words, etc in the rest of the program!
  735.  
  736. NEWTYPE.Rollover                ; custom newtype to hold rollover data
  737.   firstpicx.w                   ;  - picture 1 width
  738.   firstpicy.w                   ;  - picture 1 height
  739.   secndpicx.w                   ;  - picture 2 width
  740.   secndpicy.w                   ;  - picture 2 height
  741.   name$                         ;  - rollover name
  742.   firstpic$                     ;  - main image
  743.   secndpic$                     ;  - alternative image
  744. End NEWTYPE
  745.  
  746. Dim rolls.Rollover (#maxrolls)  ; array of rollover buttons
  747.  
  748. norolls.b=0                     ; current rollover number
  749.  
  750. MaxLen pl$=192                  ; setup LOAD ASL file requester path string
  751. MaxLen fl$=192                  ; setup LOAD ASL file requester filename string
  752.  
  753. MaxLen ps$=192                  ; setup SAVE ASL file requester path string
  754. MaxLen fs$=192                  ; setup SAVE ASL file requester filename string
  755.  
  756. pl$=imagepath$ :fl$=""          ; start image path/file
  757. ps$=savepath$  :fs$=""          ; save HTML path/file
  758.  
  759. ; -------------------------------------------------------------------------
  760. .
  761. .MainLoop
  762.  
  763. ; Main loop:
  764.  
  765. Repeat
  766.  
  767.   Select WaitEvent
  768.  
  769.     Case $100                   ; Menu hit
  770.  
  771.       Select MenuHit
  772.  
  773.         Case $0                 ; Project menu
  774.  
  775.           Select ItemHit
  776.  
  777.             Case $0             ; New Project
  778.  
  779.               If norolls>0      ; Current rollovers saved?
  780.                 lock.l=LockWindow {0}
  781.                 If Request ("Rogobox","New Project||You will lose all existing rollovers!|Are you sure?","Yes|No")
  782.                   norolls=0 ; easy :)
  783.                   WTitle "Rogobox"
  784.                 EndIf
  785.                 UnlockWindow {0,lock}
  786.               Else norolls=0:WTitle "Rogobox"
  787.               EndIf
  788.  
  789.             Case $1             ; About
  790.  
  791.               About {}
  792.  
  793.             Case $2             ; Quit
  794.  
  795.               If Quit{} Then End
  796.  
  797.           End Select
  798.  
  799.         Case $1                 ; Rollovers menu
  800.  
  801.           Select ItemHit
  802.  
  803.             Case $0             ; Create
  804.  
  805.               Gosub _Create  ; GOSUBs?!! Are you the Devil-Child?!!
  806.  
  807.             Case $1             ; Save
  808.  
  809.               Gosub _Save
  810.  
  811.           End Select
  812.  
  813.       End Select
  814.  
  815.  
  816.     Case $200                   ; close gadget hit...quit
  817.  
  818.       If Quit{} Then End
  819.  
  820. ; -------------------------------------------------------------------------
  821.  
  822.     Case $40                    ; gadget hit
  823.  
  824.       Select GadgetHit          ; but which one? do-de-do-do (Twilight Zone)
  825.  
  826.         Case $0 ; create new rollover
  827.  
  828.           Gosub _Create
  829.  
  830.         Case $1 ; save sample HTML file with rollovers
  831.  
  832.           Gosub _Save
  833.  
  834.         Case $2
  835.  
  836.           About {}
  837.  
  838.         Case $3
  839.  
  840.           If Quit{} Then End
  841.  
  842.       End Select
  843.   End Select
  844.  
  845. ; -------------------------------------------------------------------------
  846.  
  847. Forever
  848.  
  849. ; -------------------------------------------------------------------------
  850. .
  851. .Gosubs
  852.  
  853. ; Those GOSUBs in their true horror! look away! look away!
  854.  
  855. ; -------------------------------------------------------------------------
  856.  
  857. ._Create
  858.  
  859.   If norolls-1=127 Then MaxOut {}:Goto skiproll ; GOTO?!! AAAHH!! It is the Chosen One!!!
  860.   ; ^^ "semi-hacky" way of keeping my byte :)
  861.   ; basically, rollover limit reached...
  862.  
  863.     fl$="" ; reset filename each time
  864.  
  865.     ; get rollover name:
  866.     rname$="Button"+Str$(norolls+1)
  867.     If autoname=0
  868.       lock.l=LockWindow {0}
  869.       rname$=RTGetString {"Rogobox","Enter a name for this rollover:",rname$,30}
  870.       UnlockWindow {0,lock}
  871.     EndIf
  872.     If rname$="" Then Goto skiproll
  873.  
  874.     For a=0 To norolls-1
  875.       If rolls (norolls-1)\name=rname$
  876.         Request "Rogobox","That name is already in use!|Please choose another","OK"
  877.         Pop For:Goto _Create
  878.       EndIf
  879.     Next a
  880.  
  881.     rolls (norolls)\name=rname$     ; rollover name
  882.  
  883.     ; get first picture:
  884.     lock.l=LockWindow {0}
  885.     a$=ASLFileRequest$ ("Select main image:",pl$,fl$,"(#?.gif|#?.jp#?g|#?.png)")
  886.     UnlockWindow {0,lock}
  887.     If a$="" OR fl$="" Then Goto skiproll
  888.  
  889. ;   Get the image sizes; note that we only need the
  890. ;   size of the first image, since that's all that
  891. ;   gets inserted in the code!
  892.  
  893.     If imagesizes
  894.  
  895.       WTitle "Finding image sizes..."
  896.  
  897.       Dim tags.TagItem(2)
  898.       tags(0)\ti_Tag   = #DTA_SourceType, #DTST_FILE
  899.       tags(1)\ti_Tag   = #DTA_GroupID,    &GID_PICTURE$
  900.       tags(2)\ti_Tag   = #TAG_DONE
  901.       DEFTYPE.DataType *d
  902.       DEFTYPE.BitMapHeader *b
  903.       *o.b=NewDTObjectA_(&a$,tags(0))
  904.       If *o
  905.         If GetAttr_ (#PDTA_BitMapHeader,*o,&*b)
  906.           rolls (norolls)\firstpicx = Peek.w(&*b\bmh_Width)
  907.           rolls (norolls)\firstpicy = Peek.w(&*b\bmh_Height)
  908.         EndIf
  909.         DisposeDTObject_ *o
  910.       EndIf
  911.  
  912.       WTitle "Rogobox ["+Str$(norolls+1)+" created]","Rogobox"
  913.  
  914.     EndIf
  915.  
  916.     a$="file://localhost/"+a$   ; add local file crap
  917.     rolls (norolls)\firstpic=a$ ; main image name
  918.  
  919.     ; get second picture:
  920.     lock.l=LockWindow {0}
  921.     a$=ASLFileRequest$ ("Select alternative image:",pl$,fl$,"(#?.gif|#?.jp#?g|#?.png)")
  922.     UnlockWindow {0,lock}
  923.     If a$="" OR fl$="" Then Goto skiproll
  924.     a$="file://localhost/"+a$   ; add local file crap
  925.     rolls (norolls)\secndpic=a$ ; alternative image name
  926.  
  927.     ; update window title:
  928.     WTitle "Rogobox ["+Str$(norolls+1)+" created]","Rogobox"
  929.  
  930.     ; "Next!":
  931.     norolls+1
  932.  
  933.     skiproll ; something was cancelled; keep norolls...
  934.  
  935. Return
  936.  
  937. ; -------------------------------------------------------------------------
  938.  
  939. ._Save
  940.  
  941.     If norolls=0
  942.       lock.l=LockWindow {0}
  943.       Request "Rogobox","You haven't created any rollovers!","Oh yeah..."
  944.       UnlockWindow {0,lock}
  945.       Goto skipsave
  946.     EndIf
  947.  
  948.     overwriteloop ; back here in case of existing file
  949.  
  950.     f$="" ; let's not overwrite any image files :)
  951.  
  952.     lock.l=LockWindow {0} ; lock main window
  953.     a$=ASLFileRequest$ ("Save HTML file as:",ps$,fs$,"#?")
  954.     UnlockWindow {0,lock} ; unlock main window
  955.  
  956.     If a$="" OR fs$="" Then Goto skipsave
  957.  
  958.     If Exist {a$}
  959.       lock.l=LockWindow {0}
  960.       If Request ("Rogobox","Overwrite existing file?","Yes|No")=0 Then UnlockWindow {0,lock}:Goto overwriteloop
  961.       UnlockWindow {0,lock}
  962.     EndIf
  963.  
  964.     If WriteFile (0,a$) ; let's output! rock 'n' roll! etc!
  965.  
  966.       lock.l=LockWindow {0} ; lock main window
  967.  
  968.       FileOutput 0      ; write to file 0
  969.  
  970.       ; HTML demo code:
  971.  
  972. ; -------------------------------------------------------------------------
  973. .
  974. .HTMLDemo
  975.  
  976.       ; Beginning of HTML file:
  977.  
  978.       NPrint ""
  979.       NPrint "<!DOCTYPE HTML PUBLIC "+Chr$(34)+"-//W3C//DTD HTML 3.2//EN"+Chr$(34)+">"
  980.       NPrint ""
  981.       NPrint "<HTML>"
  982.       NPrint ""
  983.       NPrint "  <HEAD>"
  984.       NPrint ""
  985.       Print  "    <META HTTP-EQUIV="+Chr$(34)+"Content-Type"+Chr$(34)+" CONTENT="+Chr$(34); --> continued next line...
  986.       NPrint        "text/html;CHARSET=iso-8859-1"+Chr$(34)+">"
  987.       Print  "    <META HTTP-EQUIV="+Chr$(34)+"Generator"+Chr$(34)+" CONTENT="+Chr$(34); --> continued next line...
  988.       NPrint        "Rogobox on AMiGA!"+Chr$(34)+">"
  989.       NPrint ""
  990.       NPrint "    <SCRIPT LANGUAGE="+Chr$(34)+"Javascript"+Chr$(34)+">"
  991.       NPrint ""
  992.       NPrint "    <!-- // Hides code from non-Javascript browsers"
  993.       NPrint ""
  994.  
  995.       If preload                    ; Add image preloading code
  996.         NPrint "      if (document.images) // Preloads images"
  997.         NPrint "      {"
  998.       EndIf
  999.  
  1000. ; -------------------------------------------------------------------------
  1001.  
  1002.       ; list of images to use:
  1003.  
  1004.       For a=0 To norolls-1
  1005.         a$=rolls(a)\name
  1006.         NPrint "        var "+a$+"up = new Image(); "+a$+"up.src = "+Chr$(34)+rolls(a)\firstpic+Chr$(34)+";"
  1007.         NPrint "        var "+a$+"dn = new Image(); "+a$+"dn.src = "+Chr$(34)+rolls(a)\secndpic+Chr$(34)+";"
  1008.         If a<norolls-1 Then NPrint ""
  1009.       Next a
  1010.  
  1011.       If preload Then NPrint "      }"
  1012.  
  1013. ; -------------------------------------------------------------------------
  1014.  
  1015.       ; mouseOut (main image - button up):
  1016.  
  1017.       NPrint ""
  1018.       NPrint "      function MyMouseOutRoutine(ButtonName)"
  1019.       NPrint "      {"
  1020.       NPrint "      if (document.images)"
  1021.       NPrint "      document[ButtonName].src = eval(ButtonName + 'up.src');"
  1022.       NPrint "      }"
  1023.  
  1024. ; -------------------------------------------------------------------------
  1025.  
  1026.       ; mouseOver (alternative image - button down):
  1027.  
  1028.  
  1029.       NPrint ""
  1030.       NPrint "      function MyMouseOverRoutine(ButtonName)"
  1031.       NPrint "      {"
  1032.       NPrint "      if (document.images)"
  1033.       NPrint "      document[ButtonName].src = eval(ButtonName + 'dn.src');"
  1034.       NPrint "      }"
  1035.  
  1036. ; -------------------------------------------------------------------------
  1037.  
  1038.       ; rest of <HEAD> section:
  1039.  
  1040.       NPrint ""
  1041.       NPrint "    // Allow non-Javascript browsers to continue -->"
  1042.       NPrint ""
  1043.       NPrint "    </SCRIPT>"
  1044.       NPrint ""
  1045.       NPrint "    <TITLE>"
  1046.       NPrint "      Javascript rollover example page..."
  1047.       NPrint "    </TITLE>"
  1048.       NPrint ""
  1049.       NPrint "  </HEAD>"
  1050.       NPrint ""
  1051.  
  1052. ; -------------------------------------------------------------------------
  1053.  
  1054.       ; <BODY> section:
  1055.  
  1056.       NPrint "  <BODY BGCOLOR="+Chr$(34)+"#FFFFFF"+Chr$(34)+" TEXT="+Chr$(34)+"#000000"+Chr$(34)+">"
  1057.       NPrint ""
  1058.       NPrint "    <CENTER>"
  1059.       NPrint ""
  1060.  
  1061.       ; column of rollovers:
  1062.  
  1063.       For a=0 To norolls-1
  1064.  
  1065.       a$=StripFile{rolls(a)\name}
  1066.  
  1067.         If altname
  1068.           alt$=StripFile{rolls(a)\firstpic}
  1069.         Else alt$=rolls(a)\name
  1070.         EndIf
  1071.  
  1072.         NPrint "        <!--"+a$+" rollover-->"
  1073.         NPrint "        <A HREF="+defaultlink$
  1074.         NPrint "          onClick="+Chr$(34)+"return false;"+Chr$(34)
  1075.         NPrint "          onMouseOver="+Chr$(34)+"MyMouseOverRoutine('"+a$+"')"+Chr$(34)
  1076.         NPrint "          onMouseOut="+Chr$(34)+"MyMouseOutRoutine('"+a$+"')"+Chr$(34)+">"
  1077.         NPrint "          <IMG SRC="+Chr$(34)+rolls(a)\firstpic+Chr$(34)
  1078.         Print  "          BORDER="+Chr$(34)+Str$(border)+Chr$(34)+" ALT="+Chr$(34)+alt$+Chr$(34)
  1079.         Print            " NAME="+Chr$(34)+a$+Chr$(34)
  1080.         If imagesizes
  1081.           Print " WIDTH="+Chr$(34)+Str$(rolls(a)\firstpicx)+Chr$(34)
  1082.           Print " HEIGHT="+Chr$(34)+Str$(rolls(a)\firstpicy)+Chr$(34)
  1083.         EndIf
  1084.         NPrint          ">"
  1085.         NPrint "        </A><BR>"
  1086.         NPrint ""
  1087.       Next a
  1088.  
  1089. ; -------------------------------------------------------------------------
  1090.  
  1091.       ; end of HTML file:
  1092.  
  1093.       NPrint "    </CENTER>"
  1094.       NPrint ""
  1095.       NPrint "  </BODY>"
  1096.       NPrint ""
  1097.  
  1098.       NPrint "</HTML>"
  1099. ; -------------------------------------------------------------------------
  1100.  
  1101.       DefaultOutput:CloseFile 0
  1102.       UnlockWindow {0,lock}         ; unlock main window
  1103.       saved=norolls                 ; number saved
  1104.  
  1105.     EndIf
  1106.  
  1107.     skipsave
  1108.  
  1109. Return
  1110.